<template>
    <section class="Login">
        <div class="service-items">
            <ul>
                <li>
                    <h1>核销登录</h1>
                </li>
                <li><input type="text" v-model="loginData.account" placeholder="请输入账号"></li>
                <li><input type="password" v-model="loginData.password" placeholder="请输入密码"></li>
                <li><button type="button" @click="loginDoorStore">登录</button></li>
            </ul>
        </div>
    </section>
</template>

<script>
    import Request from "@/api/baseRequest.js";
    import { mixin_Coupon } from "@/mixins/coupon.js";
    export default {
        name: "Login",
        props: {},
        mixins: [mixin_Coupon],
        data() {
            return {};
        },
        methods: {
            rules() {
                let reg = /^(?![^a-zA-Z]+$)(?!\D+$).{8,15}$/;
                let { account, password } = this.loginData;
                if (!account) {
                    this.$Alert({ title: '信息提示', message: '账号不能为空' });
                    return false;
                }
                if (!password) {
                    this.$Alert({ title: '信息提示', message: '密码不能为空' });
                    return false;
                }
                if (!reg.test(password)) {
                    this.$Alert({ title: '信息提示', message: '字母+数字组合,至少包含一个字母和数字,长度控制在8-15' });
                    return false;
                }
                return true;
            },
            async loginDoorStore() {
                if (!this.rules()) return false;
                let params = this.loginData;
                const { code, storeId, msg } = await Request.storeLogin(params);
                if ([200, "200", "OK", 0].includes(code)) {
                    this.$Alert({ title: '信息提示', message: msg });
                    setTimeout(() => {
                        this.$router.push({ path: "/writeoff?storeId=" + storeId });
                    }, 1500);
                }
            },
        }
    };
</script>

<style lang="less" scoped>
    @import url("@/styles/login.less");
</style>
